package com.leyou.order.web;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.service.IOrderService;
import com.leyou.order.vo.OrderVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 处理请求和响应的方法
 *
 * @version V1.0
 * @package com.leyou.order.web
 * @description:
 * @author: pc
 * @date: 2019/7/13 20:00
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @PostMapping
    public ResponseEntity<Long> creatOrder(@RequestBody OrderDTO orderDTO) {
        Long orderId = orderService.creatOrder(orderDTO);
        return ResponseEntity.status(HttpStatus.CREATED).body(orderId);
    }

    @GetMapping("{orderId}")
    public ResponseEntity<OrderVO> queryOrderByOrderId(@PathVariable("orderId") Long orderId) {
        OrderVO result = orderService.queryOrderByOrderId(orderId);
        return ResponseEntity.ok(result);
    }
}
